﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>AddUserInfoView</title>
	<link href="~/layuimini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
	<link href="~/layuimini/css/layuimini.css" rel="stylesheet" />
</head>
<body>
	<div>
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">标题</label>
				<div class="layui-input-block">
					<input type="text" name="Title" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">描述</label>
				<div class="layui-input-block">
					<input type="text" name="Describe" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">等级</label>
				<div class="layui-input-block">
					<input type="text" name="Level" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">排序</label>
				<div class="layui-input-block">
					<input type="text" name="Sort" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">访问地址</label>
				<div class="layui-input-block">
					<input type="text" name="Href" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">父菜单id</label>
				<div class="layui-input-block">
					<select name="ParentId" id="menuSelect">
						<option value=""></option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">图标样式</label>
				<div class="layui-input-block">
					<input type="text" name="Icon" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">目标</label>
				<div class="layui-input-block">
					<input type="text" name="Target" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>

	<script src="~/layuimini/lib/layui-v2.6.3/layui.js"></script>
	<script>

		//页面加载完才执行里面的js代码

		layui.use('form', function () {
			var form = layui.form;
			layer = layui.layer,
				$ = layui.$;

			//异步获取菜单下拉框数据集合
			$.ajax({
                url: 'http://localhost:31861/api/MenuInfo/GetMenuInfoSelectOption',
				type: 'get',
				success: function (res) {
					if (res.isSuccess) {
						//追加新的下拉选数据
						if (res.datas && res.datas.length > 0) {
							for (var i = 0; i < res.datas.length; i++) {
								$('#menuSelect').append('<option value="' + res.datas[i].id + '">' + res.datas[i].title + '</option>');
							}
						}
						form.render('select');
					}
				}
			});
			//监听提交
			form.on('submit(formDemo)', function (data) {					//异步请求添加菜单
				$.ajax({
                    url: "http://localhost:31861/api/MenuInfo/AddMenuInfo",
					data: data.field,
					type: "post",
					success: function (result) {
						if (result.isSuccess) {
							var index = layer.alert("添加成功", {
								title: '提示'
							}, function () {
								//关闭弹出层
								layer.close(index);
								var iframeIndex = parent.layer.getFrameIndex(window.name);
								parent.layer.close(iframeIndex);

								//刷新表格数据
								parent.reLoadTable();
							});
							//其他业务
						} else {
							layer.msg(result.msg);
						}
					}
				});

				return false;
			});
		});
	</script>
</body>
</html>
